if(typeof(window.console) == 'undefined')
{
   window.console = {
      log: function(){}
   };
}

function logout()
{
   $.post(
      '/api.json',
      {method:'user.logout'},
      function(r)
      {
         authorized = false;
         switchUserLogon();
      },
      'json'
   );
}

function switchUserLogon()
{
   if(authorized)
   {
      $('#authorization_methods').hide();
      $('#authorized_as').show();
      $('#cmnt-btn').prop('disabled', false);
      switch(authorized)
      {
         case 'facebook':
            $('#authorized_as>a').attr('class','fb');
            break;
         case 'vkontakte':
            $('#authorized_as>a').attr('class','vk');
            break;
      }
   } else
   {
      $('#authorized_as').hide();
      $('#authorization_methods').show();
      $('#cmnt-btn').prop('disabled', true);
   }
}

function registerSocialUser(token, network)
{
   $.post(
      '/api.json',
      {method:'user.authorizeBySocialNetwork',data:{network:network,token:token}},
      function(r)
      {
         console.log(r);
      },
      'json'
   );
}